<%--
  Created by IntelliJ IDEA.
  User: 韩金龙
  Date: 2021/11/25
  Time: 15:25
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
        <link rel="stylesheet" href="css/css.css">
        <link rel="stylesheet" href="css/img.css">
    <script src="js/jquery-1.9.1.min.js"></script>
    <script src="js/jquery-1.8.2.min.js"></script>
    <script src="js/fileupload.js"></script>
</head>
<body>
    添加
    <form>
        车辆名称:<input type="text" name="cname"><br>
        日租金:<input type="text" name="price"><br>
        车辆图片:<div class="photoUpLoad" >
        <input type="file"   class="photo" name="photo" accept="image/*"><span class="cross">+</span>
        <img src="" alt="" class="photoEcho">
        </div><br>
        车辆明细:<input type="text" name="mx" ><br>
        车辆折扣:<input type="text" name="zk" ><br>
        车辆类型:<select name="tid">
        <option value="">请选择</option>
        </select><br>
    </form>
    <button onclick="add()">添加</button>
</body>
<script>

    $(function () {
        $.ajax({
            url:"typeList.do",
            type:"post",
            dataType:"json",
            success:function(obj) {
                console.log(obj)
                for (let i in obj) {
                    $("[name='tid']").append('<option value="'+obj[i].tid+'">'+obj[i].tname+'</option>')
                }
            }
        })
    })
    function add() {
        if ($("[name='cname']").val()==''){
            alert("名字不能为空")
            return false;
        }
        if ($("[name='price']").val()==''){
            alert("日租金不能为空")
            return false;
        }
        if ($("[name='mx']").val()==''){
            alert("明细不能为空")
            return false;
        }
        if ($("[name='zk']").val()==''){
            alert("折扣不能为空")
            return false;
        }

        var formData = new FormData($("form")[0]);
        $.ajax({
                        url:"add.do",
                        type:"post",
                        data:formData,
                        dataType:"json",
                        success:function(obj) {
                            if (obj>0){
                                alert("添加成功!!")
                                location="list.do"
                            }
                        },
                          processData:false,
                     contentType:false,
                    })
    }

</script>
</html>
